﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Twitterizer;

namespace Cecropia.BO
{

    public class TwitterBO
    {
        //Uri urlForAuth;
        //OAuthTokenResponse requestToken;

        OAuthTokens token;

        public List<AmigoTwitterDTO> ListarAmigos(string consumerKey, string consumerSecret, string AccessToken, string AccessTokenSecret, string userName)
        {
            //requestToken = OAuthUtility.GetRequestToken(consumerKey, consumerSecret, callbackAddress);
            //urlForAuth = OAuthUtility.BuildAuthorizationUri(requestToken.Token);

            //return urlForAuth.AbsoluteUri;

            token = new OAuthTokens();

            token.ConsumerKey = consumerKey;
            token.ConsumerSecret = consumerSecret;
            token.AccessToken = AccessToken;
            token.AccessTokenSecret = AccessTokenSecret;

            FriendsOptions opcoesAmigos = new FriendsOptions();
            opcoesAmigos.ScreenName = userName;

            TwitterResponse<TwitterUserCollection> listagemAmigos = TwitterFriendship.Friends(token, opcoesAmigos);

            List<AmigoTwitterDTO> lista = new List<AmigoTwitterDTO>();

            if (listagemAmigos.Result == RequestResult.Success)
            {
                foreach (TwitterUser amigo in listagemAmigos.ResponseObject)
                {
                    lista.Add(new AmigoTwitterDTO(amigo.Id, amigo.Name, amigo.ProfileImageLocation));

                }
            }

            return lista;
        }

    }


}